package com.ChenYaRou.www.controller.servlet;

import com.ChenYaRou.www.controller.GetDistrictServletController;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

import static com.ChenYaRou.www.constant.HomePage.*;

/**
 * @ClassName GetDistrictOrStreetServlet
 * @Description TODO
 * @Author 86183
 * @Date 2022/5/4 15:30
 * @Version 1.0
 **/
public class GetDistrictOrStreetServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        PrintWriter out = resp.getWriter();
        JSONObject json = JSON.parseObject(req.getParameter("json"));
        GetDistrictServletController getDistrictServletController=new GetDistrictServletController();
        if(DISTRICT.equals(json.get(MODE))){
            out.write(getDistrictServletController.getAllDistrict());
        }else if(STREET.equals(json.get(MODE))){
            out.write(getDistrictServletController.getTheStreet((String) json.get("district")));
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
